<?php
namespace app\route;
use think\Route;

if (strpos($request->url(),'Api') !== false) {
    Route::rule('widget/:ctr/:act' ,'widget/:ctr/:act'); 
}

if (!strpos($request->url(),'Api')) {
    $pages = db('WidgetPages')->select();
    if ($pages) {
        foreach ($pages as $key => $val) {
            Route::rule([$val['url_name'] => ['widget/Pages/index?url_name='.$val['url_name'],['ext'=>'html'],[]]]);
        }
    }
}